package com.example.demo.controller;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: SpringAOP
 * @ClassName JobController
 * @description:
 * @author: zsn
 * @create: 2024-11-26 14:58
 * @Version 1.0
 **/
@RestController
public class JobController {

    @Autowired
    private SchedulerFactoryBean factoryBean;
    @Autowired
    private Trigger trigger;

    @Autowired
    private JobDetail jobDetail;

    @RequestMapping("/initJob")
    public void initJob() throws SchedulerException {
        Scheduler scheduler = factoryBean.getScheduler();
        scheduler.scheduleJob(jobDetail, trigger);
        scheduler.start();
    }

}